<?php
class ErrorController extends Zend_Controller_Action {
	
	public function errorAction() {
		$this->view->headTitle()->prepend('提示信息');
		//$this->_helper->layout->setLayout('iframe');

		$errors = $this->_getParam('error_handler');
		
		if (!$errors) {
			$this->view->message = 'You have reached the error page';
			return;
		}
		
		switch ($errors->type) {
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
				
				// 404 error -- controller or action not found
				$this->getResponse()->setHttpResponseCode(404);
				$this->view->message = '找不到页面';
				break;
			default:
				// application error
				$this->getResponse()->setHttpResponseCode(500);
				$this->view->message = '应用内部错误';
				break;
		}
		
		// Log exception, if logger available
		$log = $this->getLog();
		if ($log) $log->crit('[' . $errors->exception->getCode() . '] ' . $errors->exception->getMessage() . ' [' . $this->getRequest()->getRequestURI() . ']');
		
		// conditionally display exceptions
		if ($this->getInvokeArg('displayExceptions') == true) {
			$this->view->exception = $errors->exception;
			$this->view->request = $errors->request;
		}
	}
	
	/**
	 * @return Zend_Log
	 */
	public function getLog() {
		return $this->getFrontController()->getParam('bootstrap')->getResource('log');
	}

}

